package com.sth.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sth.common.result.Result;
import com.sth.entity.Ranking;
import com.sth.service.RankingService;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 排名 前端控制器
 * </p>
 *
 * @author sith
 * @since 2024-07-11
 */
@RestController
@RequestMapping("/sth/ranking")
public class RankingController {

    @Autowired
    private RankingService rankingService;

    @ApiOperation(value = "获取明细")
    @GetMapping("/getDetailList")
    public Result findAll() {
        List<Ranking> list  = rankingService.getDetailList();
        return Result.ok(list);
    }

    @ApiOperation(value = "新增")
    @PostMapping("/save")
    public Result save(@RequestBody Ranking ranking) {
        boolean save = rankingService.save(ranking);
        return Result.ok(save);
    }

    @ApiOperation(value = "删除")
    @DeleteMapping("/remove/{id}")
    public Result remove(@PathVariable Long id) {
        rankingService.removeById(id);
        return Result.ok();
    }

    @ApiOperation(value = "获取数据")
    @GetMapping("/getList")
    public Result getList() {
        List<Ranking> list = rankingService.getList();
        return Result.ok(list);
    }
}

